package org.gap.web.jsf;

import java.util.List;

import org.gap.dao.RolesDAO;
import org.gap.dao.RolesTiersDAO;

import org.gap.domain.Roles;
import org.gap.domain.RolesTiers;

import org.gap.service.RolesService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Component;

import org.springframework.transaction.annotation.Transactional;

/**
 * Spring Component that handles CRUD requests for Roles entities
 * 
 */
@Scope("session")
@Component("RolesComponent")
public class RolesComponentImpl implements RolesComponent {

	/**
	 * Data type variable that provides CRUD operations for Roles entities
	 * 
	 */
	private Roles roles;

	/**
	 * DAO injected by Spring that manages RolesTiers entities
	 * 
	 */
	private RolesTiers rolestierses;

	/**
	 * DAO injected by Spring that manages Roles entities
	 * 
	 */
	@Autowired
	private RolesDAO rolesDAO;

	/**
	 * DAO injected by Spring that manages RolesTiers entities
	 * 
	 */
	@Autowired
	private RolesTiersDAO rolesTiersDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Roles entities
	 * 
	 */
	@Autowired
	private RolesService rolesService;

	/** 
	 */
	public RolesComponentImpl() {
	}

	/**
	 * Select an existing Roles entity
	 * 
	 */
	@Transactional
	public String selectRoles(String rolRoleKey) {
		roles = rolesDAO.findRolesByPrimaryKey(rolRoleKey);

		return "/jsf/roles/viewRoles.xhtml";
	}

	/**
	 * Save an existing RolesTiers entity
	 * 
	 */
	@Transactional
	public String saveRolesRolesTierses(String roles_rolRole, RolesTiers rolestiers) {
		roles = rolesService.saveRolesRolesTierses(roles_rolRole, rolestiers);

		return "/jsf/roles/viewRoles.xhtml";
	}

	/**
	 * Show all RolesTiers entities by Roles
	 * 
	 */
	@Transactional
	public List<RolesTiers> listRolesRolesTierses(String rolRoleKey) {
		return new java.util.ArrayList<RolesTiers>(rolesDAO.findRolesByPrimaryKey(rolRoleKey).getRolesTierses());
	}

	/**
	 * Edit an existing RolesTiers entity
	 * 
	 */
	@Transactional
	public String editRolesRolesTierses(String roles_rolRole, String related_rolestierses_rotRole, Integer related_rolestierses_rotTiers) {
		rolestierses = rolesTiersDAO.findRolesTiersByPrimaryKey(related_rolestierses_rotRole, related_rolestierses_rotTiers, -1, -1);
		return "/jsf/roles/rolestierses/editRolesTierses.xhtml";
	}

	/**
	 * Delete an existing Roles entity
	 * 
	 */
	@Transactional
	public String deleteRoles(String rolRoleKey) {
		Roles roles = rolesDAO.findRolesByPrimaryKey(rolRoleKey);
		rolesService.deleteRoles(roles);
		return "/jsf/roles/listRoless.xhtml";
	}

	/**
	 * Edit an existing Roles entity
	 * 
	 */
	@Transactional
	public String editRoles(String rolRoleKey) {
		roles = rolesDAO.findRolesByPrimaryKey(rolRoleKey);

		return "/jsf/roles/editRoles.xhtml";
	}

	/**
	 * View an existing RolesTiers entity
	 * 
	 */
	@Transactional
	public String selectRolesRolesTierses(String roles_rolRole, String related_rolestierses_rotRole, Integer related_rolestierses_rotTiers) {
		rolestierses = rolesTiersDAO.findRolesTiersByPrimaryKey(related_rolestierses_rotRole, related_rolestierses_rotTiers, -1, -1);
		return "/jsf/roles/rolestierses/viewRolesTierses.xhtml";
	}

	/**
	 * Select the Roles entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRoles(String rolRoleKey) {
		roles = rolesDAO.findRolesByPrimaryKey(rolRoleKey);

		return "/jsf/roles/deleteRoles.xhtml";
	}

	/**
	 * Delete an existing RolesTiers entity
	 * 
	 */
	@Transactional
	public String deleteRolesRolesTierses(String roles_rolRole, String related_rolestierses_rotRole, Integer related_rolestierses_rotTiers) {
		roles = rolesService.deleteRolesRolesTierses(roles_rolRole, related_rolestierses_rotRole, related_rolestierses_rotTiers);

		return "/jsf/roles/viewRoles.xhtml";
	}

	/**
	 * Create a new Roles entity
	 * 
	 */
	@Transactional
	public String newRoles() {
		roles = new Roles();

		return "/jsf/roles/createRoles.xhtml";
	}

	/**
	 * Save an existing Roles entity
	 * 
	 */
	@Transactional
	public String saveRoles(Roles roles) {
		rolesService.saveRoles(roles);
		return "/jsf/roles/listRoless.xhtml";
	}

	/**
	 * Create a new RolesTiers entity
	 * 
	 */
	@Transactional
	public String newRolesRolesTierses(String roles_rolRole) {
		rolestierses = new RolesTiers();

		return "/jsf/roles/rolestierses/createRolesTierses.xhtml";
	}

	/**
	 * Getter for variable Roles
	 * 
	 */
	@Transactional
	public RolesTiers getRolestierses() {
		return rolestierses;
	}

	/**
	 * Select the child RolesTiers entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@Transactional
	public String confirmDeleteRolesRolesTierses(String roles_rolRole, String related_rolestierses_rotRole, Integer related_rolestierses_rotTiers) {
		rolestierses = rolesTiersDAO.findRolesTiersByPrimaryKey(related_rolestierses_rotRole, related_rolestierses_rotTiers);

		return "/jsf/roles/rolestierses/deleteRolesTierses.xhtml";
	}

	/**
	 * Show all Roles entities
	 * 
	 */
	@Transactional
	public List<Roles> listRoless() {
		return new java.util.ArrayList<Roles>(rolesService.loadRoless());
	}

	/**
	 * Getter for variable Roles
	 * 
	 */
	@Transactional
	public Roles getRoles() {
		return roles;
	}

}
